﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace KinectGame
{
    public class GameContext : ApplicationContext
    {
        private int mode;
        private KinectBaseForm mainWindow;

        public GameContext(int mode, KinectBaseForm mainWindow)
        {
            int i = Options.Instance.boardSize; 
            this.mode = mode;
            this.mainWindow = mainWindow;
            if (mode == 0)
                StartMainWindow();
            if (mode == 1)
                MotionController.Instance.StartSensor(new KinectSetup(), this);
            if (mode == 2)
            {              
                VoiceController.Instance.StartSensor(this);
                StartMainWindow();                
            }
        }

        public void ApplicationMode(KinectBaseForm toClose, KinectBaseForm toOpen, int number)
        {
            toClose.Close();
            toOpen.SetGameContext(this); 
            if (this.mode == 1)
            {
                toOpen.SetupForKinectMode(); 
                MotionController.Instance.SetActiveWindow(toOpen);
            }
            if (this.mode == 2)
            {
                toOpen.SetupForKinectMode(); 
                VoiceController.Instance.SetActiveWindow(toOpen, number);
            }
            toOpen.Show(); 
        }

        public void StartMainWindow()
        {
            this.mainWindow.SetGameContext(this);
            if (this.mode == 1)
            {
                this.mainWindow.SetupForKinectMode();
                MotionController.Instance.SetActiveWindow(this.mainWindow);
            }
            if (this.mode == 2)
            {
                VoiceController.Instance.SetActiveWindow(this.mainWindow, 0);
            }
            this.mainWindow.Show();
        }

        public void ApplicationClose()
        {
            Options.Serialize(Options.Instance); 
            this.ExitThread();
        }
    }
}
